package com.moxiao.yfjh.module.blind.dal.mysql.moment;

import com.moxiao.yfjh.module.blind.controller.admin.moment.vo.BlindMemberMomentExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.moment.vo.BlindMemberMomentPageReqVO;
import java.util.*;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.module.blind.dal.dataobject.moment.BlindMemberMomentDO;
import org.apache.ibatis.annotations.Mapper;
import com.moxiao.yfjh.module.blind.controller.admin.moment.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 相亲会员动态 Mapper
 *
 * @author mx
 */
@Mapper
public interface BlindMemberMomentMapper extends BaseMapperX<BlindMemberMomentDO> {

    default PageResult<BlindMemberMomentDO> selectPage(BlindMemberMomentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BlindMemberMomentDO>()
                .eqIfPresent(BlindMemberMomentDO::getNo, reqVO.getNo())
                .eqIfPresent(BlindMemberMomentDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindMemberMomentDO::getContent, reqVO.getContent())
                .eqIfPresent(BlindMemberMomentDO::getType, reqVO.getType())
                .eqIfPresent(BlindMemberMomentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlindMemberMomentDO::getImgUrl, reqVO.getImgUrl())
                .eqIfPresent(BlindMemberMomentDO::getVideoUrl, reqVO.getVideoUrl())
                .betweenIfPresent(BlindMemberMomentDO::getCreateTime, reqVO.getCreateTime())
                .notLike(BlindMemberMomentDO::getAuditStatus,(byte) 2)
                .orderByDesc(BlindMemberMomentDO::getId));
    }

    default List<BlindMemberMomentDO> selectList(BlindMemberMomentExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BlindMemberMomentDO>()
                .eqIfPresent(BlindMemberMomentDO::getNo, reqVO.getNo())
                .eqIfPresent(BlindMemberMomentDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindMemberMomentDO::getContent, reqVO.getContent())
                .eqIfPresent(BlindMemberMomentDO::getType, reqVO.getType())
                .eqIfPresent(BlindMemberMomentDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlindMemberMomentDO::getImgUrl, reqVO.getImgUrl())
                .eqIfPresent(BlindMemberMomentDO::getVideoUrl, reqVO.getVideoUrl())
                .betweenIfPresent(BlindMemberMomentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlindMemberMomentDO::getId));
    }


    @Select("select count(*) num from blind_member_moment where no = #{momentNo}")
    Integer getMemberMomentNo(@Param("momentNo") String momentNo);

    @Select("select count(*) num from blind_member_moment where type = #{type} and user_id = #{userId} and audit_status in (0,1) and deleted = 0 ")
    Integer getMomentTypeCount(@Param("type") Integer type,
                                        @Param("userId") Long userId);

    @Select("select count(*) num from blind_member_moment where user_id = #{userId} and audit_status in (0,1) and deleted = 0")
    Integer getMomentUer(@Param("userId") Long userId);
}
